package com.ruoyi.project.service.impl;

import java.util.List;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.SecurityUtils;
import javax.annotation.Resource;
import com.ruoyi.project.mapper.FinCurrencyMapper;
import com.ruoyi.project.domain.FinCurrency;
import com.ruoyi.project.service.IFinCurrencyService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 币别Service业务层处理
 *
 * @author abel
 * @date 2024-10-15
 */
@Service
public class FinCurrencyServiceImpl implements IFinCurrencyService
{
    @Resource
    private FinCurrencyMapper finCurrencyMapper;
    /**
     * 查询币别
     *
     * @param id 币别ID
     * @return 币别
     */
    @Override
    public FinCurrency selectFinCurrencyById(Long id)
    {
        return finCurrencyMapper.selectById(id);
    }

    /**
     * 获取币别，获取不到数据抛错
     *
     * @param id 币别ID
     * @return 币别
     */
    @Override
    public FinCurrency getFinCurrencyById(Long id)
    {
        FinCurrency finCurrency = finCurrencyMapper.selectById(id);
        if(finCurrency == null){
            throw new ServiceException("币别id不正确，没有找到相关数据！");
        }
        return finCurrency;
    }

    /**
     * 查询币别列表
     *
     * @param finCurrency 币别
     * @return 币别
     */
    @Override
    public List<FinCurrency> selectFinCurrencyList(FinCurrency finCurrency)
    {
        return finCurrencyMapper.selectFinCurrencyList(finCurrency);
    }

    /**
     * 新增币别
     *
     * @param finCurrency 币别
     * @return 结果
     */
    @Override
    @Transactional
    public int insertFinCurrency(FinCurrency finCurrency)
    {
        finCurrency.setCreateTime(DateUtils.getNowDate());
        finCurrency.setCreateBy(SecurityUtils.getUsername());
        finCurrency.setCreateId(SecurityUtils.getUserId());;
        finCurrency.setUpdateBy(SecurityUtils.getUsername());
        finCurrency.setUpdateId(SecurityUtils.getUserId());
        finCurrency.setUpdateTime(DateUtils.getNowDate());
        return finCurrencyMapper.insert(finCurrency);
    }

    /**
     * 修改币别
     *
     * @param finCurrency 币别
     * @return 结果
     */
    @Override
    @Transactional
    public int updateFinCurrency(FinCurrency finCurrency)
    {
        finCurrency.setUpdateBy(SecurityUtils.getUsername());
        finCurrency.setUpdateId(SecurityUtils.getUserId());
        finCurrency.setUpdateTime(DateUtils.getNowDate());
        return finCurrencyMapper.updateById(finCurrency);
    }

    /**
     * 批量删除币别
     *
     * @param ids 需要删除的币别ID
     * @return 结果
     */
    @Override
    public int deleteFinCurrencyByIds(Long[] ids)
    {
        for(Long id:ids){
            deleteFinCurrencyById(id);
        }
        return ids.length;
    }

    /**
     * 删除币别信息
     *
     * @param id 币别ID
     * @return 结果
     */
    @Override
    public int deleteFinCurrencyById(Long id)
    {
        return finCurrencyMapper.deleteFinCurrencyById(id);
    }
}
